IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spReportsDetailedFolders_RetrieveAll')
	BEGIN
		PRINT 'Dropping Procedure spReportsDetailedFolders_RetrieveAll'
		DROP  Procedure  spReportsDetailedFolders_RetrieveAll
	END

GO

PRINT 'Creating Procedure spReportsDetailedFolders_RetrieveAll'
GO

CREATE Procedure spReportsDetailedFolders_RetrieveAll
	(
		@FILENO char(20) = null, 
		@d_folder varchar(50) = null, 
		@d_loc varchar(50) = null, 
		@d_user varchar(50) = null, 
		@doctype char(50) = null, 
		@d_status varchar(50) = null, 
		@d_datetime DateTime = null, 
		@LOCNO char(10) = null, 
		@FSTATUS char(10) = null, 
		@barcode char(20) = null, 
		@d_accno varchar(50) = null
	)
AS
    /* 
    ------------------------------------------------------------------------------
    - Change History
    - --------------
    - Date          Description
    ------------------------------------------------------------------------------
    - 10/16/2007	Initial version created
    ------------------------------------------------------------------------------
    */
	
	SET NOCOUNT ON
	
	-- Retrieve the relevant records
	SELECT  *
	FROM	ReportsDetailedFolders
	
	WHERE	(@FILENO IS NULL OR ReportsDetailedFolders.FILENO = @FILENO)
	  AND	(@d_folder IS NULL OR ReportsDetailedFolders.d_folder LIKE @d_folder + '%')
	  AND	(@d_loc IS NULL OR ReportsDetailedFolders.d_loc LIKE @d_loc + '%')
	  AND	(@d_user IS NULL OR ReportsDetailedFolders.d_user LIKE @d_user + '%')
	  AND	(@doctype IS NULL OR ReportsDetailedFolders.doctype = @doctype)
	  AND	(@d_status IS NULL OR ReportsDetailedFolders.d_status LIKE @d_status + '%')
	  AND	(@d_datetime IS NULL OR ReportsDetailedFolders.d_datetime = @d_datetime)
	  AND	(@LOCNO IS NULL OR ReportsDetailedFolders.LOCNO = @LOCNO)
	  AND	(@FSTATUS IS NULL OR ReportsDetailedFolders.FSTATUS = @FSTATUS)
	  AND	(@barcode IS NULL OR ReportsDetailedFolders.barcode = @barcode)
	  AND	(@d_accno IS NULL OR ReportsDetailedFolders.d_accno LIKE @d_accno + '%')

	-- Return to calling method
	RETURN
GO
